public class MyBlockingQueue {


    int[] array = null;

    public MyBlockingQueue() {
        array = new int[1000];
    }

    volatile int size = 0;

    int begin = 0;

    int end = 0;

    public void put(int n ) throws InterruptedException {

        synchronized(this) {
            if (size == array.length) {
                this.wait();
            }

            array[begin] = n;
            begin = (begin + 1) % array.length;
            size++;
            this.notify();
        }
    }

    public int take() throws InterruptedException {

        synchronized(this) {
            if (size == 0) {
                this.wait();
            }

            int len = array[end];
            end = (end + 1) % array.length;
            size--;
            this.notify();
            return len;
        }
    }

}
